/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

typedef struct ListNode LTNode;  
int GetLength(LTNode* head)
{
    LTNode* cur = head;
    int cnt = 0;
    while (cur)
    {
        cnt++;
        cur = cur->next;
    }
    return cnt;
}
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
    int len1 = GetLength(headA);
    int len2 = GetLength(headB);
    LTNode* fast = len1 > len2 ? headA : headB;
    int sub = len1 > len2 ? len1-len2 : len2-len1;
    while (sub--)
    {
        fast = fast->next;
    }
    LTNode* low = len1 > len2 ? headB : headA;
    while (low && fast)
    {
        if (low == fast)
            return low;        
        low = low->next;
        fast = fast->next;
    }
    return NULL;
}